<?php
/**
 * Created by PhpStorm.
 * User: luzy
 * Date: 2018/7/4
 * Time: 下午3:18
 */

class Mp_quiz_model extends Base_Model
{
    private $_redis;

    public function __construct()
    {
        parent::__construct();
    }

    public function getQuestions()
    {
        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }

        $data = igbinary_unserialize($this->_redis->get('fifatest:question:wife'));

        $randnum = array(0,1,2,3,4,5,6,7,8,9);
        shuffle($randnum);
        $randdata = array();
        for ($i=0;$i<5;$i++){
            $randdata[]=$data[$randnum[$i]];
        }
        return $randdata;
    }

    public function getHusQuestion($fuid,$sid)
    {
        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }

        $data1 = igbinary_unserialize($this->_redis->get('fifatest:question:fifa'));
        $randnum = array(0,1,2,3,4,5,6,7,8,9);
        shuffle($randnum);
        $fifadata = array();
        for ($i=0;$i<5;$i++){
            $fifadata[]=$data1[$randnum[$i]];
        }

        $data2 = igbinary_unserialize($this->_redis->get('fifatest:question:husband'));
        $data3 = igbinary_unserialize($this->_redis->get('fifatest:wifeans:'.$fuid.':'.$sid));

        $wdata = array();
        foreach ($data3 as $wa){
            $index = (int)$wa['qno']-1;
            $wdata[] = $data2[$index];
        }
        return array('fifadata'=>$fifadata,'wifedata'=>$wdata);
    }

    public function makeq($uid,$ansdata)
    {
        //生成随机key
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $randstr = "";
        for ( $i = 0; $i < 6; $i++ )  {
            $randstr .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
        }

        $dataarr = json_decode($ansdata,true);
        $datastr = igbinary_serialize($dataarr);

        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }
        //毫秒时间戳
        $mtime = microtime(true);
        $mtime *= 1000;
        $mtime = floor($mtime);
        $mtime = (string)$mtime;

        $this->_redis->multi();
        //记录老婆出题答案
        $this->_redis->set('fifatest:wifeans:'.$uid.':'.$randstr,$datastr);
        //记录老婆出题记录
        $this->_redis->zAdd('fifatest:wifeansrecord:'.$uid,time(),$randstr);
        //记录时间
        $this->_redis->set('fifatest:timerecord:share:'.$uid.':'.$randstr,$mtime);
        $this->_redis->exec();

        return $randstr;
    }

    public function getUserInfo($uid)
    {
        $this->load->database();
        $udata = $this->db->select('userName,userIcon')->from('mod_mp_user')->where('uid',$uid)->get()->row_array();
        if (strpos($udata['userIcon'],'https://')===false&&strpos($udata['userIcon'],'https://')===false){
            $udata['userIcon'] = 'https://www.nldou.com'.$udata['userIcon'];
        }
        return array('name'=>$udata['userName'],'icon'=>$udata['userIcon']);

    }

    public function saveNotifyFormid($uid,$formid)
    {
        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }
        return $this->_redis->lPush('fifatest:notify:formid:'.$uid,$formid);
    }

    public function sendNotifyMsg($mpid,$fuid,$uid,$sid,$timestr)
    {
        $this->load->database();
        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }

        //完成时间
        $finish = date('Y-m-d H:i:s',time());
        //获取老婆openid
        $fudata = $this->db->select('openid')->from('mod_mp_openid')->where(array('uid'=>$fuid,'source'=>$mpid))->get()->row_array();
        $openid = $fudata['openid'];
        //获取老公的昵称
        $udata = $this->db->select('userName')->from('mod_mp_user')->where(array('uid'=>$uid))->get()->row_array();
        $husname = "老公".$udata['userName'];
        //获取formid
        $formid = $this->_redis->lPop('fifatest:notify:formid:'.$fuid);
        //获取tempid
        $tempid = "l-1d5Ucvms6SL1_eCccqahMXARxRimwujygwL7FcKuM";/*服务进度通知*/
        $tempdata = array(
            "keyword1"=>array("value"=>$husname),/*发起人*/
            "keyword2"=>array("value"=>"你的老公在".$timestr."内打开链接，并完成你出的问题"),/*服务状态*/
            "keyword3"=>array("value"=>$finish),/*完成时间*/
            "keyword4"=>array("value"=>'你的老公究竟了解足球多点还是你多点？你是不是真的混得还不如个"球"呢？赶紧点击查看测试结果吧~~')/*备注*/
        );
        //获取目标页面
        $page = 'pages/result/result?fuid='.$fuid.'&sid='.$sid.'&uid='.$uid.'&fromhus=0';
        if ($formid!==false){
            $this->load->model('mp_model');
            $this->mp_model->setAppParams($mpid);
            $this->mp_model->sendMsg($openid,$tempid,$tempdata,$formid,$page);
        }
    }

    public function saveOpenTime($uid,$fuid,$sid)
    {
        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }
        //毫秒时间戳
        $mtime = microtime(true);
        $mtime *= 1000;
        $mtime = floor($mtime);
        //存储打开时间
        $this->_redis->zAdd('fifatest:timerecord:open:'.$fuid.':'.$sid,$mtime,$uid);
    }

    public function getPostUrl($uid,$fuid,$sid)
    {
        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }
        return $this->_redis->get('fifatest:post:'.$fuid.':'.$sid.':'.$uid);
    }

    public function getResults($uid,$fuid,$sid,$husans,$mpid)
    {
        if (!isset($this->redis_model)){
            $this->load->model('redis_model');
            $this->_redis=$this->redis_model->getRedisInstance();
        }

        $husansarr = json_decode($husans,true);
        $husansstr = igbinary_serialize($husansarr);
        $this->_redis->multi();
        //获取老婆分享时间
        $this->_redis->get('fifatest:timerecord:share:'.$fuid.':'.$sid);
        //获取老公打开时间
        $this->_redis->zScore('fifatest:timerecord:open:'.$fuid.':'.$sid,$uid);
        //存储老公答案
        $this->_redis->set('fifatest:husans:'.$fuid.':'.$sid.':'.$uid,$husansstr);
        //获取老婆答案
        $this->_redis->get('fifatest:wifeans:'.$fuid.':'.$sid);
        //获取FIFA题目答案
        $this->_redis->get('fifatest:question:rightans:fifa');
        $res = $this->_redis->exec();

        $sharetime = (int)$res[0];
        $opentime = (int)$res[1];
        $wifeans = igbinary_unserialize($res[3]);
        $fifarightans = igbinary_unserialize($res[4]);
        //计算老公打开时间
        $time = $opentime-$sharetime;
        $timesec = ceil($time/1000);
        $timearr = $this->getTimeArr($timesec);
        //保存到榜单
        $this->_redis->zAdd('fifatest:timerank',$time,$uid);
        //计算老公FIFA题目的正确数
        $corfifacnt = 0;
        foreach ($husansarr['fifa'] as $hfans){
            $qi = 'q'.$hfans['qno'];
            $corans = (int)$fifarightans[$qi];
            $qans = (int)$hfans['val'];
            if ($qans===$corans) $corfifacnt++;
        }
        $wiferightans = array();
        //重整老婆答案
        foreach ($wifeans as $wans){
            $qi = 'q'.$wans['qno'];
            $wiferightans[$qi]=(int)$wans['val'];
        }
        //计算老公WIFE题目的正确数
        $corwifecnt = 0;
        foreach ($husansarr['wife'] as $hwans){
            $qi = 'q'.$hwans['qno'];
            $corans = $wiferightans[$qi];
            $qans = (int)$hwans['val'];
            if ($qans===$corans) $corwifecnt++;
        }
        //计算星级
        $fstar = $this->getRankStar($corfifacnt);
        $wstar = $this->getRankStar($corwifecnt);
        //计算时间排名
        $this->_redis->multi();
        $this->_redis->zRank('fifatest:timerank',$uid);
        $this->_redis->zCard('fifatest:timerank');
        $res=$this->_redis->exec();
        $rank = (int)$res[0];
        $ranktotalnum = (int)$res[1];
        $overrank = $ranktotalnum-$rank;
        $rankper = round($overrank/$res[1],2)*100;
        $rankper = $rankper.'%';
        //生成海报
        $posturl = $this->createPost($uid,$fuid,$sid,$fstar,$wstar,$timearr,$rankper);
//        $posturl = '';

//        return array('time'=>$time,'timestr'=>$timearr,'share'=>$sharetime,'open'=>$opentime,'fifastar'=>$fstar,'wifestar'=>$wstar,
//            'rank'=>$rank,'ranktotalnum'=>$ranktotalnum,'rankper'=>$rankper,'posturl'=>$posturl);
        //保存海报
        $this->_redis->set('fifatest:post:'.$fuid.':'.$sid.':'.$uid,$posturl);
        //发送通知
        $this->sendNotifyMsg($mpid,$fuid,$uid,$sid,$timearr['text']);
        return array('posturl'=>$posturl);

    }

    public function getTimeArr($timesec)
    {
        $timearr = array();
        if ($timesec<10){
            $timearr['text']=$timesec.'秒';
            $timearr['size']= '40';
            $timearr['hor'] = '132';
            $timearr['vrt'] = '965';
        }elseif ($timesec<100){
            $timearr['text']=$timesec.'秒';
            $timearr['size']= '35';
            $timearr['hor'] = '127';
            $timearr['vrt'] = '970';
        }elseif ($timesec<1000){
            $timearr['text']=$timesec.'秒';
            $timearr['size']= '30';
            $timearr['hor'] = '122';
            $timearr['vrt'] = '975';
        }elseif ($timesec<3600){
            $timearr['text']=$timesec.'秒';
            $timearr['size']= '25';
            $timearr['hor'] = '122';
            $timearr['vrt'] = '980';
        }else{
            $timearr['text']='>3600秒';
            $timearr['size']= '20';
            $timearr['hor'] = '122';
            $timearr['vrt'] = '980';
        }
        return $timearr;
    }

    public function getRankStar($cor)
    {
        if ($cor<1){
            return 1;
        }elseif ($cor<3){
            return 2;
        }elseif ($cor<5){
            return 3;
        }else{return 4;}
    }

    public function downloadUserIcon($uid)
    {
        $this->load->database();
        $udata = $this->db->select('userIcon')->from('mod_mp_user')->where('uid',$uid)->get()->row_array();
        $url = $udata['userIcon'];

        if (strpos($url,'https://')===false&&strpos($url,'http://')===false){
            $filepath = '/home/nldou/webroot/web'.$url;
            $dir = '/upload/images/usericon/';
            $filename = substr($url,strlen($dir));
            $fdir = '/home/nldou/webroot/web'.$dir;
            return array('filepath'=>$filepath,'filename'=>$filename,'fdir'=>$fdir);
        }else{
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_NOBODY, 0);//对body进行输出
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $package = curl_exec($ch);
            $httpinfo = curl_getinfo($ch);

            curl_close($ch);
            $media = array_merge(array('header'=>$httpinfo),array('body' => $package));

            //生成文件名
            preg_match('/\w\/(\w+)/i', $media["header"]["content_type"], $extmatches);
            $fileExt = $extmatches[1];
            $filename = md5(time().uniqid()).".{$fileExt}";

            $dir = "/upload/images/usericon/";
            $fdir = '/home/nldou/webroot/web'.$dir;

            file_put_contents($fdir.$filename,$media['body']);

            $dbpath = $dir.$filename;
            $this->db->update('mod_mp_user',array('userIcon'=>$dbpath),array('uid'=>$uid));
            $filepath = $fdir.$filename;
            return array('filepath'=>$filepath,'filename'=>$filename,'fdir'=>$fdir);
        }


    }

    public function createPost($uid,$fuid,$sid,$fifastar,$wifestar,$timearr,$rankper)
    {
        $this->load->model('post_model');
        $postdir = "/home/nldou/webroot/web/upload/images/act/fifatest/";
        $filename = "f".$fuid."a".$uid."s".$sid."t".time().".png";//海报文件名
        $postpath=$postdir.$filename;

        //下载头像
        $icon = $this->downloadUserIcon($uid);
        //调整头像大小
        $config1 = array();
        $config1['source_image']=$icon['filepath'];//源文件地址
        $iconpath=$icon['fdir'].'154-'.$icon['filename'];//处理后地址
        $config1['new_image']=$iconpath;
        $config1['height']='154';
        $config1['width']='154';
        $this->post_model->resize($config1);
        //overlay通用设置
        $config2=array();
        $config2['wm_vrt_alignment']='top';
        $config2['wm_hor_alignment']='left';
        $config2['wm_type']='overlay';
        $config2['wm_opacity']='100';
        //加fifa题目结果
        $config2['source_image']=$postdir."source/rankpost-bg.png";//海报模板地址
        $config2['new_image']=$postpath;
        $config2['wm_overlay_path']=$postdir."source/rankpost-fifa-".$fifastar.".png";
        $config2['wm_hor_offset']='0';
        $config2['wm_vrt_offset']='512';
        $this->post_model->overlay($config2);
        //加wife题目结果
        $config2['source_image']=$postpath;
        $config2['new_image']=$postpath;
        $config2['wm_overlay_path']=$postdir."source/rankpost-wife-".$wifestar.".png";
        $config2['wm_hor_offset']='375';
        $config2['wm_vrt_offset']='512';
        $this->post_model->overlay($config2);
        //加头像
        $config2['source_image']=$postpath;
        $config2['new_image']=$postpath;
        $config2['wm_overlay_path']=$iconpath;
        $config2['wm_hor_offset']='299';
        $config2['wm_vrt_offset']='570';
        $this->post_model->overlay($config2);

        $config3 = array();
        $config3['wm_vrt_alignment']='top';
        $config3['wm_hor_alignment']='left';
        $config3['wm_type']='text';
        $config3['wm_opacity']='100';
        $config3['wm_font_path']="/home/nldou/webroot/web/fonts/yaheibold.ttf";
        $config3['wm_font_color']='30517b';
        //加打开时间
        $config3['source_image']=$postpath;
        $config3['new_image']=$postpath;
        $config3['wm_text']=$timearr['text'];
        $config3['wm_font_size']=$timearr['size'];
        $config3['wm_hor_offset']=$timearr['hor'];
        $config3['wm_vrt_offset']=$timearr['vrt'];
        $this->post_model->overlay($config3);
        //加排名
        $config3['source_image']=$postpath;
        $config3['new_image']=$postpath;
        $config3['wm_text']=$rankper;
        $config3['wm_font_size']='40';
        $config3['wm_hor_offset']='496';
        $config3['wm_vrt_offset']='1010';
        $this->post_model->overlay($config3);


        $posturl = "https://www.nldou.com/upload/images/act/fifatest/".$filename;

        return $posturl;
    }

//    public function createRandData()
//    {
//        if (!isset($this->redis_model)){
//            $this->load->model('redis_model');
//            $this->_redis=$this->redis_model->getRedisInstance();
//        }
//        for ($i=0;$i<100;$i++){
//            $uid = mt_rand(5000,6000);
//            $time = mt_rand(5000,10000);
//            $this->_redis->zAdd('fifatest:timerank',$time,$uid);
//            echo ($i+1);
//            echo "  uid:".$uid." time:".$time.PHP_EOL;
//        }
//    }

    /*public function saveQdata()
    {
        $wifidata = array(
            array(
                "qno"=>1,
                "question"=>"以下哪个家务是你最不喜欢的？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"洗碗"),
                    array("val"=>2,"ans"=>"做饭"),
                    array("val"=>3,"ans"=>"洗衣服"),
                    array("val"=>4,"ans"=>"我老公从来不让我做家务"),
                )
            ),
            array(
                "qno"=>2,
                "question"=>"你老公哪一点最吸引你？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"颜值"),
                    array("val"=>2,"ans"=>"智商高"),
                    array("val"=>3,"ans"=>"情商高"),
                    array("val"=>4,"ans"=>"我老公太完美了，哪儿哪儿都好"),
                )
            ),
            array(
                "qno"=>3,
                "question"=>"你最不接受以下哪一项？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"让老公帮忙，喊了几遍，他动也不动"),
                    array("val"=>2,"ans"=>"老公永远不承认自己的错误"),
                    array("val"=>3,"ans"=>"老公太懒"),
                    array("val"=>4,"ans"=>"老公没情调"),
                )
            ),
            array(
                "qno"=>4,
                "question"=>"老公陪你逛街，你希望他？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'在楼下咖啡店等你，你随便逛'),
                    array("val"=>2,"ans"=>"主动拎包，及时给出很忠恳的建议"),
                    array("val"=>3,"ans"=>"主动把信用卡给你，让你随便刷"),
                    array("val"=>4,"ans"=>"跟在身后，默默地刷手机"),
                )
            ),
            array(
                "qno"=>5,
                "question"=>"你看中了一件衣服，但你老公不太喜欢，你希望他怎样做？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'诚实地告诉你"这件衣服你穿不好看"'),
                    array("val"=>2,"ans"=>'委婉地告诉你"再看看别的吧"'),
                    array("val"=>3,"ans"=>'果断买下，并跟你讲"你穿什么都好看"'),
                    array("val"=>4,"ans"=>'不做评论，跟你讲"你自己穿的，你自己决定呗"'),
                )
            ),
            array(
                "qno"=>6,
                "question"=>"吵架如果是你的错，你会？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'希望老公跟我讲"千错万错都是他的错"'),
                    array("val"=>2,"ans"=>"主动向老公承认错误"),
                    array("val"=>3,"ans"=>"希望老公告诉我错在哪里，以后不要再犯同样的错误"),
                    array("val"=>4,"ans"=>"大丈夫不与小女子计较，希望老公给个台阶让我下"),
                )
            ),
            array(
                "qno"=>7,
                "question"=>'老公看球时，你对他讲"我口渴了"，你希望他？',
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'提醒我"渴了就喝水啊"'),
                    array("val"=>2,"ans"=>"立马去帮我倒一杯温度适宜的水"),
                    array("val"=>3,"ans"=>"自己去倒水，顺便帮老公也倒一杯"),
                    array("val"=>4,"ans"=>"老公看球，我还是别打扰")

                )
            ),
            array(
                "qno"=>8,
                "question"=>"最近你在减肥，让老公帮你带个饭，你希望他？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"买你最爱吃的，长肉也愿意"),
                    array("val"=>2,"ans"=>"买卡路里低的食物 ，不要做你减肥路上的绊脚石"),
                    array("val"=>3,"ans"=>"全家就是我家，遇见什么买什么"),
                    array("val"=>4,"ans"=>'直接给你讲"减肥还吃什么吃，家里不是有黄瓜嘛"')
                )
            ),
            array(
                "qno"=>9,
                "question"=>"七夕节快到了，你希望你老公？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'给你讲"都老夫老妻了，有什么好过的"'),
                    array("val"=>2,"ans"=>'给你讲"七夕是商家用来忽悠人的，不要上当"'),
                    array("val"=>3,"ans"=>"提前选好你可能会喜欢的礼物"),
                    array("val"=>4,"ans"=>"礼物什么不重要，有这份心意最重要")
                )
            ),
            array(
                "qno"=>10,
                "question"=>"你回家和你老公抱怨你领导，这时你希望他？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'安慰你"领导都这样，习惯了就好"'),
                    array("val"=>2,"ans"=>'主动帮你分析领导为什么会这样'),
                    array("val"=>3,"ans"=>'给你讲"老婆辛苦了，咱们出去吃顿好的"'),
                    array("val"=>4,"ans"=>'给你讲"既然有这么多抱怨，就别干了，我养你"')
                )
            )
        );
        $husbanddata = array(
            array(
                "qno"=>1,
                "question"=>"以下哪个家务是你老婆最不喜欢的？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"洗碗"),
                    array("val"=>2,"ans"=>"做饭"),
                    array("val"=>3,"ans"=>"洗衣服"),
                    array("val"=>4,"ans"=>"我从来不让老婆做家务"),
                )
            ),
            array(
                "qno"=>2,
                "question"=>"你觉得你最吸引你老婆的地方是？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"颜值"),
                    array("val"=>2,"ans"=>"智商高"),
                    array("val"=>3,"ans"=>"情商高"),
                    array("val"=>4,"ans"=>"我太完美了，哪儿哪儿都好"),
                )
            ),
            array(
                "qno"=>3,
                "question"=>"你老婆最不接受以下哪一项？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"让你帮忙，喊了几遍，你动也不动"),
                    array("val"=>2,"ans"=>"你永远不承认自己的错误"),
                    array("val"=>3,"ans"=>"你太懒"),
                    array("val"=>4,"ans"=>"你没情调"),
                )
            ),
            array(
                "qno"=>4,
                "question"=>"陪老婆逛街，你会？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'告诉老婆"我在楼下咖啡店等你，你随便逛"'),
                    array("val"=>2,"ans"=>"主动拎包，及时给出她希望听到的建议"),
                    array("val"=>3,"ans"=>"主动把信用卡给老婆，让老婆随便刷"),
                    array("val"=>4,"ans"=>"跟在身后，默默地刷手机"),
                )
            ),
            array(
                "qno"=>5,
                "question"=>"老婆看中了一件衣服，但你觉得不好看，老婆征求你意见时，你会？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'诚实地告诉老婆"这件衣服你穿不好看"'),
                    array("val"=>2,"ans"=>'委婉地告诉老婆"再看看别的吧"'),
                    array("val"=>3,"ans"=>'果断买下，并跟老婆讲"你穿什么都好看"'),
                    array("val"=>4,"ans"=>'不做评论，跟老婆讲"你自己穿的，你自己决定呗"'),
                )
            ),
            array(
                "qno"=>6,
                "question"=>"吵架如果是老婆的错，你会？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'跟老婆讲"千错万错都是我的错"'),
                    array("val"=>2,"ans"=>"等她自己承认错误"),
                    array("val"=>3,"ans"=>"让老婆认识到她错在哪里，以后不要再犯同样的错误"),
                    array("val"=>4,"ans"=>"大丈夫不与小女子计较，给个台阶让她下"),
                )
            ),
            array(
                "qno"=>7,
                "question"=>'看球时，老婆对你讲"我口渴了"，你会？',
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'提醒老婆"渴了就喝水啊"'),
                    array("val"=>2,"ans"=>"立马去帮老婆倒一杯温度适宜的水"),
                    array("val"=>3,"ans"=>"让老婆顺便帮我也倒一杯"),
                    array("val"=>4,"ans"=>"目不转睛，继续看球")

                )
            ),
            array(
                "qno"=>8,
                "question"=>"最近老婆在减肥，让你帮她带个饭，你会？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"人生就是需要放纵的，必须买老婆最爱吃的 "),
                    array("val"=>2,"ans"=>"减肥也要注意营养搭配，买卡路里低的食物"),
                    array("val"=>3,"ans"=>"全家就是我家，随便买个便当"),
                    array("val"=>4,"ans"=>'给老婆讲"减肥还吃什么吃，家里不是有黄瓜嘛"')
                )
            ),
            array(
                "qno"=>9,
                "question"=>"七夕节快到了，你会？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'给老婆讲"都老夫老妻了，有什么好过的"'),
                    array("val"=>2,"ans"=>'给老婆讲"七夕是商家用来忽悠人的，不要上当"'),
                    array("val"=>3,"ans"=>"提前选好老婆可能会喜欢的礼物"),
                    array("val"=>4,"ans"=>"下班路上，遇见什么买什么，心意最重要")
                )
            ),
            array(
                "qno"=>10,
                "question"=>"老婆回家和你抱怨她领导，这时你会？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>'安慰老婆"领导都这样，习惯了就好"'),
                    array("val"=>2,"ans"=>'主动帮老婆分析领导为什么会这样'),
                    array("val"=>3,"ans"=>'给老婆讲"老婆辛苦了，咱们出去吃顿好的"'),
                    array("val"=>4,"ans"=>'给老婆讲"既然有这么多抱怨，就别干了，我养你"')
                )
            )
        );
        $fifadata = array(
            array(
                "qno"=>1,
                "question"=>"以下哪只球队没参加本届世界杯？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"瑞典"),
                    array("val"=>2,"ans"=>"埃及"),
                    array("val"=>3,"ans"=>"意大利"),
                    array("val"=>4,"ans"=>"法国"),
                )
            ),
            array(
                "qno"=>2,
                "question"=>"本届世界杯小组赛唯一一场0:0出现在哪一场？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"巴西vs瑞士"),
                    array("val"=>2,"ans"=>"法国vs丹麦"),
                    array("val"=>3,"ans"=>"日本vs波兰"),
                    array("val"=>4,"ans"=>"比利时vs英格兰"),
                )
            ),
            array(
                "qno"=>3,
                "question"=>"本届世界杯小组赛犯规最多的一场比赛是哪一场？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"韩国vs瑞典"),
                    array("val"=>2,"ans"=>"法国vs澳大利亚"),
                    array("val"=>3,"ans"=>"巴西vs瑞士"),
                    array("val"=>4,"ans"=>"日本vs哥伦比亚"),
                )
            ),
            array(
                "qno"=>4,
                "question"=>"本届世界杯小组赛进球最多的球队是？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"英格兰"),
                    array("val"=>2,"ans"=>"法国"),
                    array("val"=>3,"ans"=>"巴西"),
                    array("val"=>4,"ans"=>"比利时"),
                )
            ),
            array(
                "qno"=>5,
                "question"=>"本届世界杯小组赛失球最少的球队是？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"巴西"),
                    array("val"=>2,"ans"=>"法国"),
                    array("val"=>3,"ans"=>"乌拉圭"),
                    array("val"=>4,"ans"=>"丹麦"),
                )
            ),
            array(
                "qno"=>6,
                "question"=>"本届世界杯小组赛传球最多的球队是？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"巴西"),
                    array("val"=>2,"ans"=>"德国"),
                    array("val"=>3,"ans"=>"西班牙"),
                    array("val"=>4,"ans"=>"阿根廷"),
                )
            ),
            array(
                "qno"=>7,
                "question"=>"本届世界杯第一张红牌出现在哪场比赛？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"德国vs瑞典"),
                    array("val"=>2,"ans"=>"日本vs哥伦比亚"),
                    array("val"=>3,"ans"=>"乌拉圭vs俄罗斯"),
                    array("val"=>4,"ans"=>"丹麦vs法国"),
                )
            ),
            array(
                "qno"=>8,
                "question"=>"本届世界杯小组赛犯规最少的球队是？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"巴西"),
                    array("val"=>2,"ans"=>"日本"),
                    array("val"=>3,"ans"=>"西班牙"),
                    array("val"=>4,"ans"=>"德国"),
                )
            ),
            array(
                "qno"=>9,
                "question"=>"以下哪支球队没有进入本届世界杯16强？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"巴西"),
                    array("val"=>2,"ans"=>"法国"),
                    array("val"=>3,"ans"=>"乌拉圭"),
                    array("val"=>4,"ans"=>"德国"),
                )
            ),
            array(
                "qno"=>10,
                "question"=>"本届世界杯小组赛失球最多的球队是？",
                "ansarr"=>array(
                    array("val"=>1,"ans"=>"巴拿马"),
                    array("val"=>2,"ans"=>"沙特"),
                    array("val"=>3,"ans"=>"埃及"),
                    array("val"=>4,"ans"=>"摩洛哥"),
                )
            )
        );
        $fifadataright = array(
            'q1'=>3,
            'q2'=>2,
            'q3'=>1,
            'q4'=>4,
            'q5'=>3,
            'q6'=>3,
            'q7'=>2,
            'q8'=>2,
            'q9'=>4,
            'q10'=>1
        );
        $this->load->model('redis_model');
        $redis=$this->redis_model->getRedisInstance();
        $str = igbinary_serialize($fifadataright);
        $redis->set('fifatest:question:rightans:fifa',$str);

    }*/

}